﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Ares.Engine
{
    public static class ExtensionHelper
    {
        /// <summary>
        /// Includes the trailing path delimiter.
        /// </summary>
        /// <param name="InputPath">The input path.</param>
        /// <returns>The input path including a trailing path delimiter if it doesn't have one</returns>
        public static string IncludeTrailingPathDelimiter(this string InputPath)
        {
            if (!InputPath.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
                !InputPath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
                return InputPath + Path.DirectorySeparatorChar;
            return InputPath;
        }
        /// <summary>
        /// Asserts the trailing path delimiter.
        /// </summary>
        /// <param name="InputPath">The input path.</param>
        public static void AssertTrailingPathDelimiter(this string InputPath)
        {
            InputPath = InputPath.IncludeTrailingPathDelimiter();
        }
        /// <summary>
        /// Trims the extension from a file name.
        /// </summary>
        /// <param name="InputFile">The input file.</param>
        public static void TrimExtension(this string InputFile)
        {
            int start, count;
            if ((start = InputFile.LastIndexOf(".")) > 0)
            {
                count = InputFile.Length - start;
                InputFile = InputFile.Remove(start, count);
            }
        }
        /// <summary>
        /// Gets a file extension of a filename.
        /// </summary>
        /// <param name="InputFile">The input file.</param>
        /// <returns>The file extension</returns>
        public static string FileExtension(this string InputFile)
        {
            int start, count;
            if ((start = InputFile.LastIndexOf(".")) > 0)
            {
                count = InputFile.Length - start;
                return InputFile.Substring(start, count);
            }
            return string.Empty;
        }
    }
}
